package tw.com.diray;

import tw.com.diray.set.ModfiyPassswordFragment;
import tw.com.diray.set.UserInfoFragment;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.ActionBar.TabListener;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.Menu;
import android.view.MenuInflater;

/**
 * 設定
 * 
 * @author Andy
 * 
 */
public class DirarySettingActivity extends FragmentActivity implements
		TabListener {

	static final int NUM_ITEMS = 10;
	private ViewPager viewPager;

	private String[] title = new String[] { "基本設定", "設定密碼" };

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		this.setContentView(R.layout.activity_dir_setting_view);

		final ActionBar actionBar = getActionBar();

		actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

		this.viewPager = (ViewPager) this.findViewById(R.id.pager);

		viewPager.setAdapter(new AppSectionsPagerAdapter(
				getSupportFragmentManager()));

		viewPager.setOnPageChangeListener(new OnPageChangeListener() {

			@Override
			public void onPageSelected(int position) {
				getActionBar().setSelectedNavigationItem(position);

			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onPageScrollStateChanged(int arg0) {
				// TODO Auto-generated method stub

			}
		});

		// Add 3 tabs, specifying the tab's text and TabListener
		for (int i = 0; i < 2; i++) {
			actionBar.addTab(actionBar.newTab().setText(title[i])
					.setTabListener(this));
		}

	}

	public static class AppSectionsPagerAdapter extends
			android.support.v4.app.FragmentPagerAdapter {

		public AppSectionsPagerAdapter(FragmentManager fm) {
			super(fm);
			// TODO Auto-generated constructor stub
		}

		@Override
		public Fragment getItem(int arg0) {

			switch (arg0) {
			case 0:
				return new UserInfoFragment();

			default:

				return new ModfiyPassswordFragment();
			}

		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return 2;
		}

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public void onTabSelected(Tab tab, FragmentTransaction ft) {
		this.viewPager.setCurrentItem(tab.getPosition());
	}

	@Override
	public void onTabUnselected(Tab tab, FragmentTransaction ft) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onTabReselected(Tab tab, FragmentTransaction ft) {
		// TODO Auto-generated method stub

	}
}
